{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\colortbl ;\red255\green0\blue0;}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\i\f0\fs22 Tutorial: Run Code\b\i0\par
Goal: Guide the robot home\b0\par
You give the computer instructions called \b code\b0 . When the computer \b runs\b0  \b code\b0  it performs the instructions.\par
1) Copy the code below into the Code Area:\par
2) Click the Run Button.\par
3) After you complete the goal, click the Next Button to move on.\par
\i\par
Tutorial: Fix Syntax Error\b\i0\par
Goal: Guide the robot home\par
\b0 If you write invalid code the computer will report a \b syntax error\b0 .\par
1) Copy the code below into the Code Area (it intentionally contains errors):\par
2) The next step will hide these instructions. Click the Mission Tab to return here.\par
3) Click the Run Button.\par
4) In the Syntax Error Tab, click the 'Line:' hyperlink to find the error. Click the 'Help' hyperlink for more information.\par
5) Fix the syntax error in the code.\par
6) Click the Run Button.\par
7) After you complete the goal, click the Next Button to move on.\par
\par
\i Tutorial: Exception\par
\b\i0 Goal: Guide the robot home\par
\b0 If your code is grammatically correct but nonsensical, the computer will \b raise an exception\b0 .\par
1) Copy the code below into the Code Area (it intentionally contains errors):\par
2) The next step will hide these instructions. Click the Mission Tab to return here.\par
3) Click the Run Button.\par
4) In the Exception Tab, click the hyperlinks for more information.\par
6) Fix the code so it does not throw an exception.\par
7) Click the Run Button.\par
8) After you complete the goal, click the Next Button to move on.\par
\par
\i Tutorial: Fix Logic\i0\par
\b Goal: Guide the robot home\par
\b0 Your code may not accomplish its goal. You'll need to find what's wrong and fix it, a process called \b debugging\b0 .\par
1) Copy the code below into the Code Area:\par
2) Click the Run Button. The code will not complete the goal.\par
3) Click the Reset Button.\par
4) Fix the code. How does the robot need to move to get home?\par
5) Click the Run Button.\par
6) After you complete the goal, click the Next Button to move on.\par
\i\par
\i0 [\i Recap\par
\b\i0 Goal: Guide the robot home\par
\b0 1) Copy the code below into the Code Area (it intentionally contains errors):\par
2) Click the run button.\par
3) Fix the syntax error, the exception, and debug the logic.\par
4) After you complete the goal, click the Next Button to move on.]\i\par
\par
Function Calls\i0\par
\b Goal: Guide the robot home\par
\b0 A \b function call\b0  performs the predefined instructions stored in a \b function\b0 . To call the function named 'moveUp' write:\par
moveUp();\par
The semicolon only finishes the instruction. It is not part of the function call.\par
1) Look in the Library for available functions. Click the hyperlinks to see more information.\par
2) Write code to guide the robot home. Use function calls.\par
3) Click the Run Button.\par
4) After you complete the goal, click the Next Button to move on.\par
\par
\i Function Calls: One Parameter\i0\par
\b Goal: Guide the robot home\par
\b0 Certain function calls require extra information, called a \b parameter\b0 . To pass '4' to the function 'moveUp' write:\par
moveUp(4);\par
For now, all parameters will be whole numbers from -2147483648 to 2147483647 called \b integers\b0 ,\b  \b0 abbreviated to \b int\b0 .\par
1) Click the function hyperlinks in the Library. Notice all of the functions now require a 'distance' parameter which is of type int.\par
2) Copy the code below into the Code Area.\par
moveRight(-2);\par
3) Fix the code to guide the robot home.\par
4) After you complete the goal, click the Next Button to move on.\par
\par
\i Function Calls: Multiple Parameters\par
\b\i0 Goal: Guide the robot home\par
\b0 Certain function calls require more than one parameter. To pass -1 and 1 to the function 'move' write:\par
move(-1, 1);\par
Notice the order of parameters matters. The code above is different from:\par
move(1, -1);\par
1) Click the 'move' function hyperlink in the library. Notice the function requires an 'x' and 'y' parameter. Understand what the 'x' and 'y' parameters do.\par
2) Copy the code below into the Code Area.\par
moveRight(-1, 1);\par
3) Fix the code to guide the robot home.\par
4) After you complete the goal, click the Next Button to move on.\par
\par
\i Function Calls: Rest Parameters\par
\b\i0 Goal: Output 1, 2, 3, 4.\par
Rest parameters\b0  are zero or more optional parameters after the required parameters. The 'output' function can be called with:\par
output();\par
output(1);\par
output(9, 12);\par
output(9, 12, 15, 27, 1239);\par
Rest parameters can be any type of data but for now will only be integers.\par
1) Click the 'output' function hyperlink in the library. Notice the function takes '... arguments'. This means the function takes rest parameters.\par
2) Write code to call the 'output' function with the parameters: 1, 2, 3, 4.\par
4) After you complete the goal, click the Next Button to move on.\par
\par
\i Single Line Comment\par
\b\i0 Goal: Guide the robot home\b0\par
Two forward slashes, such as:\par
//moveUp();\par
turn all remaining code in the line into a \b comment\b0 . The computer will not decode, called \b compiling\b0 , or run comments.\par
1) Copy the code below into the Code Area:\par
moveUp();\par
moveRight();\par
2) <a href="event:highlight:runButton">Run</a> the code.\par
3) Add a // before the 'moveUp' function call:\par
//moveUp();\par
moveRight();\par
5) Run the code.\par
6) After you complete the goal, click the Next Button to move on.\par
\par
\i Block Comment\par
\b\i0 Goal: Guide the robot home\par
\b0 /* turns all code until */ into a \b block comment\b0 . The computer will not compile or execute block comments.\par
(1) Copy the following code into the Code Area:\par
moveRight();\par
moveUp();\par
(2) <a href="event:highlight:runButton">Run</a> the code.\par
(3) Comment out all of the code by adding a /* before the code and */ after the code like:\par
/*moveRight();\par
moveUp();*/\par
(5) Run the code.\par
(6) Click the Next Button to move on.\par
\par
\i Integer Constants\par
\b\i0 Goal: Buy one hat for each cat.\b0\par
In code, you can create an integer by writing that integer. For example:\par
4; //creates 4 and does nothing with it.\par
6; //creates 6 and does nothing with it.\par
12; //creates 12 and does nothing with it.\par
Explicitly writing an integer is called an \b integer constant.\par
\b0 1) Copy the code below:\par
buyHats(0);\par
2) Fix the code to achieve the goal.\par
3) Run the code and when the goal is accomplished, click Next.\par
\par
\i Integer Expressions\par
\b\i0 Goal: Buy one hat for each cat.\par
\b0 Any code that creates an integer value is called an \b integer expression\b0 . Some function calls create integers values. For example:\par
output(4); //outputs 4\par
output(createFour()); //outputs 4\par
Here the function call createFour() is an integer expression, because it creates then becomes the integer value 4.\par
1) Copy the code below:\par
buyHats(4);\par
2) Replace the integer constant 4 with the function call to createFour().\par
3) Run the code.\par
4) After you achieve the goal, press Next to move on.\par
\par
\i Return Values\par
\i0 The value a function creates is called a \b return value\b0 . Unlike an integer constant, you can't be sure what value a function will return. However, the library and name of the function should give you a good idea. For example:\par
output(add(2, 2)); //outputs 4 probably?\par
1) Click the 'add' function in the library. Notice the function ends with ':int'. This means the function returns an integer value. Notice the 'Returns' section explains the meaning of the return value.\par
2) Copy the code below:\par
buyHats(0);\par
3) Replace the integer constant 0 with the function call add(). Choose any two parameters for 'add' that will accompish the goal.\par
4) After you achieve the goal, press Next to move on.\par
----\par
\i Evaluation: Constants\par
\b\i0 Goal: Output 3\par
\b0 Certain code becomes a value, called \b evaluating \b0 to a value. An \b integer constant\b0 , which is just a written integer, evaluates to that integer.\par
output(4); //4 evaluates to 4.\par
1) Using integer constants and function calls, write code to output the integer 3.\par
2) After you complete the goal, click the Next Button to move on.\par
\i\par
Evaluation: Return Values\par
\b\i0 Goal: Output the sum of 1 and 2\par
\b0 Certain function calls evaluate to a value, called a\b  return value\b0 . In the code below, assume the function 'add' evaluates to the sum of its parameters:\par
output(add(2, 2));  //outputs 4\par
The code 'add(2, 2)' becomes the integer value 4.\par
1) Click the 'add' function in the library. Notice the function ends with ':int'. This means the function returns an integer value. Notice the 'Returns' section explains the meaning of the return value.\par
2) Write code to call the 'output' function with the return value of add(1, 2). Use the return value of 'add' and NOT the integer constant 3.\par
3) After you complete the goal, click the Next Button to move on.\par
\i\par
Evaluation: Expression\b\i0\par
Goal: Output 7\par
\b0 Any code that evaluates to an integer is called an \b integer expression\b0 . An integer expression behaves just like an integer. For example, 'add(3, 4)' is an integer expression that evaluates to 7. The following are all valid:\par
output(7); //outputs 7\par
output(add(3, 4)); //outputs 7\par
output(add(3, add(2, 2)); //outputs 7\par
'add(3, add(2,2)' evaluates to 'add(3 , 4)' which evaluates to 7.\par
1) Write code to output 7. Do not use the integer constant 7. For example:\par
output(add(3, 4));\par
output(add(add(1, 2), 4));\par
2) After you complete the goal, click the Next Button to move on.\b\par
\b0\i\par
Evaluation: Return Values\par
\b\i0 Goal: Output the number of cats\par
\b0 1) Click the 'getCatCount' function in the library. Notice the function ends with ':int'. This means the function returns an integer value. Notice the 'Returns' section explains the meaning of the return value.\par
2) Write code to call the 'output' function with the number of cats. Try using the return value of 'getCatCount' and NOT integer constants.\par
3) After you complete the goal, click the Next Button to move on.\par
\i\par
Output Function\par
\b\i0 Goal: Output 1, getTwo()\par
\b0 The 'output' function will output the value of any expression. This is useful for seeing what value an expression evaluates to.\par
1) Write code to achieve the goal.\par
2) After you complete the goal, click the Next Button to move on.\par
\i\par
Coding Process\par
\b\i0 Goal: Buy one hat for each cat\par
\b0 Most coding problems can be solved by following these steps:\par
(1) Understand the goal.\par
(2) Find useful existing code and language features.\par
(3) Simplify goal steps until it is codable using items found in step 2.\par
(4) Write code.\par
(5) Test code and fix it until the goal is achieved.\par
1) Follow the steps above to achieve the goal. Hint: Use the Library for step #2.\par
2) Click the Next button to move on.\par
\i\par
Test Cases\i0\par
\b Goal: Buy one hat for each cat (*3)\par
\b0 To prove that code is robust and reusable, it is often run against a variety of situations called \b test cases\b0 . Well written code should achieve the goal in all reasonable situations.\par
1) Notice the Goal has '(*3)'. This means there are three test cases against which your code must achieve the goal.\par
2) Copy the code below and run it:\par
buyHats(1);\par
3) Notice the code succeeds when there is 1 cat but fails when there are 2 cats.\par
4) Fix the code so it succeeds regardless of the number of cats.\par
5) Click the Next button to move on.\par
\par
\i Using the Code Process\i0\par
\b Goal: Buy four mittens for each kitten (*3)\par
1) Understand the goal.\b0  We want four mittens per kitten. That means we want to buy a number of mittens equal to four times the number of kittens.\par
\b 2) Find useful existing code and language features.\b0  Looking in the library, we see the functions 'getKittenCount', 'output', 'multiply' and 'buyMittens'. We know we can use the following language features: function calls, parameters, return values and numeric constants.\par
\b 3) Simplify goal steps until codable using items from step 2.\par
4) Write code.\par
\b0 Take the problem one step at a time. You need to buy mittens. Write:\par
buyMittens();\par
'buyMittens' requires an integer parameter called 'mittenCount'. How many mittens do we need? Four multiplied by the number of kittens. But, going one step at a time we write:\par
buyMittens(multiply(,));\par
What are we multiplying? Four and the number of kittens. So we write:\par
buyMittens(multiply(4, ));\par
And what are we multiplying by four? The number of kittens. So we write:\par
buyMittens(multiply(4, getKittenCount());\par
\b 5) Test code and fix it until the goal is achieved.\par
\b0 6) Click the Next Button to move on.\b\par
\b0\i\par
Using the Code Process II\par
\b\i0 Goal: Guide the robot home (*3)\par
\b0 Remember to follow the Coding Process:\par
1) Understand the goal.\par
2) Find useful existing code and language features.\par
3) Simplify goal steps until codable using items from step 2.\par
4) Write code.\par
5) Test code and fix it until the goal is achieved.\par
Hint: If the robot is at X position 5 and you want it at position 2, you move the robot -3 spaces. 2 minus 5 equals -3.\par
\i\par
Operators\par
\b\i0 Goal: Raise the net to catch the shooting star.\par
\b0 1) Copy the code below into the code area:\par
raiseNet(4);\par
2) Click the Run Button. Notice the net catches the star.\par
3) Click the Next Button to move on.\cf1\par
\par
\cf0\i Addition Operator\par
\b\i0 Goal: Shoot the asteroid at the right time (without using 'add()')  (*3)\par
\b0 The '+' symbol, called the \b addition operator, \b0 adds two integer expressions and evaluates to their sum. For example:\par
output(3 + 4); //outputs 7\par
output(3 + 4 + 5); //outputs 12\par
output(getLauncherX() + 6);\par
1) Copy the code below into the Code Area:\par
shootAt(add(5, getTime()), 3);\par
2) Convert the code to use the addition operator instead of the 'add()' function call.\par
3) Click the Next Button to move on.\par
\par
\i Subtraction Operator\par
\b\i0 Goal: Output 5 minus getX() (without using 'subtract()') (*3)\par
\b0 The '-' symbol, called the \b subtraction operator\b0 , subtracts two integer expressions and evaluates to their difference. For example:\par
output(4 - 3); //outputs 1\par
output(3 - 4 - 2); //outputs -3\par
output(getLauncherX() - 6);\par
1) Copy the code below into the Code Area:\par
output(subtract(5, getX()));\par
2) Convert the code to use the subtraction operator instead of the 'subtract()' function call.\par
3) Click the Next Button to move on.\par
\par
\i Subtraction Operator: Negation\i0\par
\b Goal: Output negative getX() (without using 'negate()') (*3)\par
\b0 The subtraction operator, the '-' symbol, can also negate a single integer expression and evaluates to the opposite signed integer. For example:\par
output(-3); //outputs -3\par
output(3 + -4); //outputs -1\par
output(-getLauncherX());\par
1) Copy the code below into the Code Area:\par
output(negate(getX()));\par
2) Convert the code to use the subtraction operator instead of the 'negate()' function call.\par
3) Click the Next Button to move on.\par
Multiply\par
Divide (& Number!)\par
Modulo\par
Parenthesis and Order of Operations\par
\cf1\par
White Space\par
Math Operators\par
Booleans\par
Control Statements\par
\cf0\par
}
 